Ext.define('App.controller.lable.LableViewController', {
	extend : 'Ext.app.ViewController',
	alias : 'controller.lableViewController',
	menu : Ext.widget('menu'),
	control : {
		'lableView lableSearch basesearchform' : {
			beforerender : function(form) {
				var buttons = {
					'bs/lable/saveLable' : function(permit) {
                        var lableTypeId = form.down("lableTypeSingleSelect").down("[itemId=lableTypeId]").getValue();
                        if(!lableTypeId){
                            BaseUtil.toast("请选择标签类型");
                            return;
                        }
                        var name = form.down("[name=name]").getValue();
                        if(!name){
                            BaseUtil.toast("请填写标签名");
                            return;
                        }
                        BaseUtil.post(permit.url,function(data){
                            BaseUtil.toast(data.msg);
                            Ext.StoreMgr.get('lable.LableStore').reload();
                        },form.getValues());
					},
                    'bs/lable/updateLable' : function(permit) {
                        var lableTypeId = form.down("lableTypeSingleSelect").down("[itemId=lableTypeId]").getValue();
                        if(!lableTypeId){
                            BaseUtil.toast("请选择标签类型");
                            return;
                        }
                        var name = form.down("[name=name]").getValue();
                        if(!name){
                            BaseUtil.toast("请填写标签名");
                            return;
                        }
                        BaseUtil.post(permit.url,function(data){
                            BaseUtil.toast(data.msg);
                            Ext.StoreMgr.get('lable.LableStore').reload();
                        },form.getValues());
                    }
				};
				BaseUtil.createPermitBar(form, buttons);
			},
			render : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('lable.LableStore'),Ext.getCmp('lableView').down('lableSearch form').getForm().getFieldValues());
			},

		},
        'lableView lableList':{
            itemclick:function(view, record, item, index, e, eOpts){
                var search  =  Ext.getCmp('lableView').down('lableSearch form');
                search.reset();
                search.loadRecord(record);
                search.down("lableTypeSingleSelect").down("[itemId=lableTypeId]").setValue(record.get("lableTypeId"));
                search.down("lableTypeSingleSelect").down("[itemId=lableName]").setValue(record.get("lableName"));
            },
        },
		'lableView lableSearch [action=search] ' : {
			click : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('lable.LableStore'),Ext.getCmp('lableView').down('lableSearch form').getForm().getFieldValues());
			}
		}
	}
});